//
// Copyright (c) 2014, 保留所有权利。
//
// SingleSync.java
//
// 作    者：王红燕
// 当前版本：1.0
// 2014 下午5:03:43
//
//
package com.vanke.agent.tools;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

import com.vanke.agent.sync.AgentSync;
import com.vanke.agent.sync.AreaCompanySync;
import com.vanke.agent.sync.BookingSync;
import com.vanke.agent.sync.BuildingSync;
import com.vanke.agent.sync.CompanySync;
import com.vanke.agent.sync.ContractSync;
import com.vanke.agent.sync.EmpInfoSync;
import com.vanke.agent.sync.GetInSync;
import com.vanke.agent.sync.HpointSync;
import com.vanke.agent.sync.MemberSync;
import com.vanke.agent.sync.OrderSync;
import com.vanke.agent.sync.ProjectSync;
import com.vanke.agent.sync.ReceiveSync;
import com.vanke.agent.sync.RoomSync;

/**
 *
 */
public class SingleSync {
	static Map<String, AgentSync> cmdSyncMap = new HashMap<String, AgentSync>();
	static Map<String, String> cmdDescMap = new LinkedHashMap<String, String>();

	static {
		init("recv", new ReceiveSync(), "同步跟进记录");
		init("booking", new BookingSync(), "同步认筹");
		init("order", new OrderSync(), "同步认购");
		init("contract", new ContractSync(), "同步签约");
		init("getin", new GetInSync(), "同步款项");
		init("room", new RoomSync(), "同步房产");
		init("project", new ProjectSync(), "同步项目");
		init("area", new AreaCompanySync(), "同步区域公司");
		init("ek", new CompanySync(), "同步公司");
		init("empinfo", new EmpInfoSync(), "同步员工");
		init("member", new MemberSync(), "同步会员");
		init("point", new HpointSync(), "同步会员积分");
		init("buiding", new BuildingSync(), "同步楼栋");
	}

	static void init(String cmd, AgentSync sync, String desc) {
		cmdSyncMap.put(cmd, sync);
		cmdDescMap.put(cmd, desc);
	}

	public static void main(String[] args) {
		if (args.length != 1) {
			usage();
			return;
		}
		String cmd = args[0].trim();
		AgentSync sync = cmdSyncMap.get(cmd);
		if (sync == null) {
			usage();
			return;
		}
		sync.sync();
	}

	private static void usage() {
		System.out.println("./sync.sh cmd");
		System.out.println("  cmd：要执行一次同步的命令，可取值如下");
		Iterator<Entry<String, String>> iter = cmdDescMap.entrySet().iterator();
		while (iter.hasNext()) {
			Entry<String, String> entry = iter.next();
			String line = String.format("      %-8s: %s", entry.getKey(),
					entry.getValue());
			System.out.println(line);
		}
	}
} //~

